<ng-include src="'{:U('Index/header')}'"></ng-include>
<div id="b-doc">
    <div class="c-cat" ng-controller="DocCatController">
        <div class="title" ng-click="load(0)">
            <a href="" class="plus" ng-click="edit(0,$event)" data-toggle="tooltip" data-placement="top"
               title="添加分类" data-step="1" data-intro="点击这里添加分类"><span class="fa fa-plus"></span></a>
            <span class="fa fa-th-list"></span>
            文档分类
        </div>
        <div class="list">
            <div class="item" ng-repeat="item in docCatService.data" ng-click="load(item.id)"
                 ng-class="{cur:item.id==docService.cat_id}" ng-show="item.id &gt; 0">
                <a href="#" class="operation" ng-click="edit(item.id,$event)" data-toggle="tooltip"
                   data-placement="top"
                   title="修改/删除"><span
                        class="fa fa-pencil"></span></a>
                <span>{{item.title}}({{item.doc_cnt}})</span>
            </div>
        </div>
        <!--分类编辑弹出框开始-->
        <div class="modal fade" id="cat-edit">
            <div class="modal-dialog modal-sm">
                <div class="modal-content">
                    <form ng-submit="submit()" novalidate="novalidate" name="form">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                    aria-hidden="true">&times;</span></button>
                            <h4 class="modal-title">{{data.id > 0 ? '编辑': '添加'}}</h4>
                        </div>
                        <div class="modal-body">
                            <div class="form-group"
                                 ng-class="{'has-error':!form.title.$pristine && form.title.$invalid && !form.title.$focused}">
                                <label for="title" class="control-label">名称:</label>
                                <input type="text" class="form-control" id="title" name="title" ng-model="data.title"
                                       required ng-focus/>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default btn-danger" ng-click="delete()"
                                    ng-show="data.id>0">删除
                            </button>
                            <button type="submit" class="btn btn-primary" ng-disabled="form.$invalid">保存</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <!--分类编辑弹出框结束-->
    </div>
    <div class="c-list" ng-controller="DocListController">
        <div class="title">
            <a ng-show="docService.one.id &gt; 0" href="" class="plus" ng-click="edit(0)"><span
                    class="fa fa-plus"></span>新建文档</a>
        </div>
        <div class="search">
            <i class="fa fa-search"></i>
            <input type="text" class="form-control" placeholder="搜索标题" ng-model="docService.search.keywords" />
        </div>
        <div class="list">
            <div class="item doc-list-item" ng-repeat="item in docService.data" ng-click="edit(item.id)"
                 ng-class="{cur:item.id==docService.one.id}">
                <div class="tools" ng-show-on-hover-parent=".doc-list-item">
                    <a href="" class="delete flag-stop-propagation" ng-click="delete(item.id)"><span
                            class="fa fa-remove"></span></a>
                </div>
                <div class="title">
                    {{item.title}}
                </div>
                <div class="attr">
                    添加:{{item.add_time}}
                </div>
                <div class="attr">
                    修改:{{item.update_time}}
                </div>
                <div class="desc">
                    {{item.summary}}
                </div>
            </div>
            <div class="list-loading">
                玩命加载...
            </div>
        </div>
    </div>
    <div class="c-body" ng-controller="DocBodyController">
        <div class="tool-box">
            <div class="cat-box" data-step="2" data-intro="选择文档分类">
                <select class="form-control" ng-model="docService.one.cat_id"
                        ng-options="item.id as item.title for item in docCatService.data">
                </select>
            </div>
            <div class="title-box" data-step="3" data-intro="输入文档标题">
                <input type="text" name="doc_title" id="doc_title" ng-model="docService.one.title"
                       class="form-control" placeholder="在这里输入新文档标题"/>
            </div>
            <div class="export-box">
                <a class="btn btn-primary btn-xs command-submit" id="command-submit" href="" ng-click="submit()"
                   data-toggle="tooltip"
                   data-placement="top" title="保存" data-step="5" data-intro="保存你的文档"><i
                        class="fa fa-save"></i></a>
                <a href="__ROOT__<?php if(C('URL_MODEL')!=2){echo '?s=';} ?>/r/{{docService.one.out_id}}:preview"
                   target="_blank"
                   data-toggle="tooltip" data-placement="top" title="访问网页版"
                   ng-show="docService.one.out_id" class="btn btn-default btn-xs"><i
                        class="fa fa-desktop"></i></a>
                <a href="__ROOT__<?php if(C('URL_MODEL')!=2){echo '?s=';} ?>/r/{{docService.one.out_id}}:mobile"
                   target="_blank"
                   data-toggle="tooltip" data-placement="top" title="访问手机版"
                   ng-show="docService.one.out_id" class="btn btn-default btn-xs"><i
                        class="fa fa-mobile fa-lg"></i></a>
                <a href="__ROOT__<?php if(C('URL_MODEL')!=2){echo '?s=';} ?>/r/download/out_id/{{docService.one.out_id}}"
                   target="_blank"
                   data-toggle="tooltip" data-placement="top" title="下载HTML"
                   ng-show="docService.one.out_id" class="btn btn-default btn-xs"><i class="fa fa-html5"></i></a>
                <a href="__ROOT__<?php if(C('URL_MODEL')!=2){echo '?s=';} ?>/r/{{docService.one.out_id}}:pdf"
                   target="_blank"
                   data-toggle="tooltip" data-placement="top" title="生成PDF"
                   ng-show="docService.one.out_id" class="btn btn-default btn-xs"><i class="fa fa-file"></i></a>
                <a href="" data-toggle="tooltip" data-placement="top" title="历史版本"
                   ng-show="docService.one.out_id" class="btn btn-default btn-xs" ng-click="history()"><i
                        class="fa fa-clock-o"></i></a>
                <if condition="tpx_config_get('wordpress_syncer_enable')">
                    <a href="" data-toggle="tooltip" data-placement="top" title="发布到Wordpress"
                       ng-show="docService.one.out_id && (docService.one.wp_id==0)" class="btn btn-default btn-xs"
                       ng-click="wordpressPublish()"><i
                            class="fa fa-cloud-upload"></i></a>
                    <a href="" data-toggle="tooltip" data-placement="top" title="同步到Wordpress"
                       ng-show="docService.one.wp_id>0" class="btn btn-default btn-xs" ng-click="wordpressSync($event)"
                       data-tpl="<?php echo t_html(tpx_config_get('wordpress_syncer_preview_url')); ?>"><i
                            class="fa fa-retweet"></i></a>
                    <a href="" data-toggle="tooltip" data-placement="top" title="断开与Wordpress关联"
                       ng-show="docService.one.wp_id>0" class="btn btn-default btn-xs"
                       ng-click="wordpressUnlink($event)"><i
                            class="fa fa-unlock"></i></a>
                </if>
            </div>
        </div>
        <div class="mdeditor-box" data-step="4" data-intro="填写Markdown文件">
            <iframe src="{:U('Doc/editor')}" id="iframe_editor" name="iframe_editor" data-fullscreen="false"></iframe>
        </div>
        <a href="" ng-click="fullscreen()" class="btn-fullscreen btn btn-default btn-xs" data-toggle="tooltip"
           data-placement="left"
           title="编辑器全屏（F11）"><img
                src="__ASSERTS__/res/img/icon_fullscreen.png"/></a>

        <if condition="tpx_config_get('wordpress_syncer_enable')">
            <!--Wordpress发布弹出框开始-->
            <div class="modal fade" id="wordpress-publish">
                <div class="modal-dialog modal-sm">
                    <div class="modal-content">
                        <form ng-submit="wordpressPublishSubmit()" novalidate="novalidate" name="form">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                        aria-hidden="true">&times;</span></button>
                                <h4 class="modal-title">Wordpress发布</h4>
                            </div>
                            <div class="modal-body">
                                <script type="text/ng-template" id="nodes_renderer.html">
                                    <div ui-tree-handle>
                                        <input type="checkbox" name="wordpress_categorys" id="category-{{node.id}}"
                                               value="{{node.id}}"/>
                                        <label for="category-{{node.id}}">
                                            {{node.title}}
                                        </label>
                                    </div>
                                    <ul ui-tree-nodes="" ng-model="node.nodes">
                                        <li ng-repeat="node in node.nodes" ui-tree-node
                                            ng-include="'nodes_renderer.html'">
                                        </li>
                                    </ul>
                                </script>
                                <div ui-tree class="categorys-tree">
                                    <ul ui-tree-nodes="" ng-model="data_wordpress_categorys" id="tree-root">
                                        <li ng-repeat="node in data_wordpress_categorys" ui-tree-node
                                            ng-include="'nodes_renderer.html'"></li>
                                    </ul>
                                </div>
                            </div>
                            <div class="modal-footer">
                                <button type="submit" class="btn btn-primary" ng-disabled="form.$invalid">保存</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
            <!--Wordpress发布弹出框结束-->
        </if>
        <!--历史编辑框开始-->
        <div class="modal fade" id="body-history">
            <div class="modal-dialog modal-sm">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title">{{docService.one.title}} 历史版本</h4>
                    </div>
                    <div class="modal-body">
                        <div class="bg-info">
                            <b>提示：</b>系统会保存最近的{$data_history_size}个版本
                        </div>
                        <div class="panel panel-default" ng-repeat="item in docService.history_data">
                            <div class="panel-heading">
                                <a href="" ng-click="historyRestore(item.id)" ng-show="item.id != -1" class="pull-right"
                                   data-toggle="tooltip"
                                   data-placement="top"
                                   title="恢复该版本到编辑器"><i
                                        class="fa fa-undo"></i></a>
                                # {{ item.update_time }}
                            </div>
                            <div class="panel-body">
                                <pre data-toggle="tooltip"
                                     data-placement="top"
                                     title="点击查看全部" ng-click="historyShow($event)" ng-bind-html="item.content_diff">{{ item.content_diff }}</pre>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!--历史编辑框结束-->
        </div>
    </div>
</div>